<template>
  <div class="fileCard">
    <div class="fileIcon">
      <img :src="getFileImage()" alt="" />
    </div>
    <div class="info">
      <div class="title" :title="info.file_name">{{ info.file_name }}</div>
      <div class="attribute">
        <div class="size">{{ info.file_size }}</div>
        <div class="tm">{{ info.time || "--" }}</div>
      </div>
    </div>
    <div class="btn" v-if="isHistory">
      <i class="iconfont icon-yunduanxiazai" @click="downLoadFile"></i>
      <i class="iconfont icon-yulan" @click="priview"></i>
    </div>
  </div>
</template>

<script>
import { downLoad } from "@/utils/index";
export default {
  components: {},
  props: {
    info: {
      type: Object,
      default: () => ({}),
    },
    isHistory: {
      type: Boolean,
      default: true,
    },
  },
  data() {
    return {};
  },
  mounted() {
    // console.log(this.info, "this.info");
  },
  methods: {
    downLoadFile() {
      downLoad(this.info.file_name, this.info.file_url);
      // let aDom = document.createElement("a");
      // aDom.style.display = "none";
      // aDom.href = this.info.file_url;
      // aDom.setAttribute("download", this.info.file_name);
      // document.body.appendChild(aDom);
      // aDom.click();
      // document.body.removeChild(aDom);
    },
    getFileImage() {
      if (!this.info.file_name) {
        console.log(this.info);
      }
      return require(`@/assets/image/window/${this.info.file_name.split(".").at(-1)}.png`);
    },
    priview() {
      this.$emit("priview", this.info);
    },
  },
};
</script>
<style lang="scss" scoped>
.fileCard {
  width: 336px;
  height: 58px;
  margin-left: 65px;
  background: #fff;
  border-radius: 8px;
  display: flex;
  align-items: center;
  padding: 5px 0px;
  box-sizing: border-box;
  margin-top: 5px;
  .fileIcon {
    width: 45px;
    margin-left: 3px;
    background: rgba(131, 150, 181, 0.1);
    border-radius: 3px;
    img {
      width: 25px;
      height: 28px;
      padding: 8px 10px;
    }
  }
  .info {
    width: calc(100% - 65px - 45px - 25px);
    margin-left: 15px;
    .title {
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
      text-align: left;
      font-size: 16px;
      //   max-width: 80%;
    }
    .attribute {
      display: flex;
      color: rgba(0, 20, 45, 0.5);
      font-size: 12px;
      margin-top: 3px;
      > div {
        flex: 1;
        text-align: left;
      }
      :nth-child(2) {
        padding-left: 20px;
        border-left: 1px solid rgba(0, 20, 45, 0.1);
      }
    }
  }
  .btn {
    width: 65px;
    margin-left: 0px;
    > i {
      font-size: 18px;
      margin-left: 8px;
      cursor: pointer;
      &:hover {
        color: rgba(55, 111, 255, 1);
      }
    }
  }
}
</style>
